{% extends "login/base.html" %}

{% block subject %}
    <link rel="stylesheet" href="/static/css/reg.css">
    <div class="login-box">
        <div class="reg-box">
            <h1 class="Welcome"> 欢迎注册 </h1>
            <p>已有账号? <a href="/login/"> 请登录</a></p>
        </div>
        <div class="login-form">
            {% csrf_token %}
            {% for foo in form %}
                <div class="inp-div">
                    <label for=""> {{ foo.label }} </label>
                    {{ foo }}
                    <span class="error"></span>
                </div>
            {% endfor %}
            <button id="but">注 册</button>
        </div>
    </div>
    <script>
    $('#but').click(function(){
        $.ajax({
            url:"",
            type:"post",
            data:{
                username:$("#id_username").val(),
                password:$("#id_password").val(),
                var_pwd:$("#id_var_pwd").val(),
                email:$("#id_email").val(),
                csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val(),
            },
            success:function(res){
                if(res.user){
                    location.href="/login/"
                } else {
                    $(".error").html("").parent().removeClass("has-error");
                    $.each(res.error, function (i, j) {
                        $("#id_" + i).next().html(j[0]).prev().addClass("has-error");
                    })
                }
            }
        })
    })
    </script>
{% endblock %}



